//
//  ViewController.m
//  TestCallC
//
//  Created by mac on 2025/9/4.
//

#import "ViewController.h"
#import "test.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Do any additional setup after loading the view.
    testC();
    
    @autoreleasepool {
        NSString *objectiveCString = @"Tbatt: 10\nVbatt: 20\nIbatt: 30";
        const char *cString = [objectiveCString UTF8String];
        BatmanData *result = processBatman(cString);
        if (result != NULL) {
            NSString *tbatt = [NSString stringWithUTF8String:result->Tbatt];
            NSString *vbatt = [NSString stringWithUTF8String:result->Vbatt];
            NSString *ibatt = [NSString stringWithUTF8String:result->Ibatt];
            NSLog(@"Tbatt: %@", tbatt);
            NSLog(@"Vbatt: %@", vbatt);
            NSLog(@"Ibatt: %@", ibatt);
            // 释放C结构体中分配的内存
            if (result->Tbatt != NULL) {
                free(result->Tbatt);
            }
            if (result->Vbatt != NULL) {
                free(result->Vbatt);
            }
            if (result->Ibatt != NULL) {
                free(result->Ibatt);
            }
            free(result);
        }
    }
}


- (void)setRepresentedObject:(id)representedObject {
    [super setRepresentedObject:representedObject];

    // Update the view, if already loaded.
}


@end
